home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubmalm.zip / tenner.ub < prev    next >
Text File  |  1990-08-22  |  612b  |  17 lines

  1.    10   *Tenner(N,&A(),&Leng,&F)
  2.    20   ' Tenner"s algorithm for the continued fraction of n^(1/2).
  3.    25   ' Returns leng = -1 for error.
  4.    30   ' Modeled on the Pascal version.
  5.    40   ' 4 May 1990
  6.    50   local Ub%=200,U,Uu,V,Vv,Sqn
  7.    60   if N<1 then Leng=-1:return endif
  8.    70   F=1:Leng=0:Sqn=isqrt(N):A(0)=Sqn
  9.    80   U=N-Sqn*Sqn:if U=0 then return endif
  10.   100   V=Sqn:Vv=V:Uu=U
  11.   110   repeat
  12.   120   inc Leng:if Leng>Ub% then dec Leng:F=0:return endif
  13.   140   A(Leng)=(Sqn+V)\U:V=U*A(Leng)-V
  14.   150   U=(N-V*V)\U
  15.   160   until and{V=Vv,U=Uu}
  16.   170   return ' End of subroutine Tenner.
  17.